package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(BookList booklist) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入新增书名：");
        String name = sc.nextLine();
        System.out.println("请输入作者：");
        String author = sc.nextLine();
        System.out.println("请输入类型：");
        String type = sc.nextLine();
        System.out.println("请输入价格：");
        int price = sc.nextInt();

        Book book = new Book(name,author,price,type);

        int currentSize = booklist.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book temp = booklist.getBook(i);
            if(temp.getName().equals(name)){
                System.out.println("该书已存在，无需添加！");
                return;
            }

        }
        booklist.setBook(book);
        booklist.setUsedSize(currentSize + 1);
    }
}
